package com.ng.common.component.engine.enums;

/**
 * 比较运算符枚举
 * 定义了数值比较时可用的所有运算符
 * 
 * 包含六种基本比较运算：
 * - 等于 (EQUALS)
 * - 不等于 (NOT_EQUALS)
 * - 大于 (GREATER_THAN)
 * - 小于 (LESS_THAN)
 * - 大于等于 (GREATER_OR_EQUAL)
 * - 小于等于 (LESS_OR_EQUAL)
 */
public enum CompareOperator {
    /** 等于运算符 (==) */
    EQUALS,
    
    /** 不等于运算符 (!=) */
    NOT_EQUALS,
    
    /** 大于运算符 (>) */
    GREATER_THAN,
    
    /** 小于运算符 (<) */
    LESS_THAN,
    
    /** 大于等于运算符 (>=) */
    GREATER_OR_EQUAL,
    
    /** 小于等于运算符 (<=) */
    LESS_OR_EQUAL;

    /**
     * 获取运算符的符号表示
     * @return 运算符对应的数学符号
     */
    public String getSymbol() {
        switch (this) {
            case EQUALS:
                return "==";
            case NOT_EQUALS:
                return "!=";
            case GREATER_THAN:
                return ">";
            case LESS_THAN:
                return "<";
            case GREATER_OR_EQUAL:
                return ">=";
            case LESS_OR_EQUAL:
                return "<=";
            default:
                return "";
        }
    }

    /**
     * 判断是否为相等性比较运算符
     * @return 如果是EQUALS或NOT_EQUALS返回true，否则返回false
     */
    public boolean isEqualityOperator() {
        return this == EQUALS || this == NOT_EQUALS;
    }

    /**
     * 判断是否为顺序比较运算符
     * @return 如果是比较大小的运算符返回true，否则返回false
     */
    public boolean isOrderingOperator() {
        return this == GREATER_THAN || this == LESS_THAN 
            || this == GREATER_OR_EQUAL || this == LESS_OR_EQUAL;
    }

    /**
     * 获取运算符的反向运算符
     * @return 对应的反向运算符
     */
    public CompareOperator getOpposite() {
        switch (this) {
            case EQUALS:
                return NOT_EQUALS;
            case NOT_EQUALS:
                return EQUALS;
            case GREATER_THAN:
                return LESS_OR_EQUAL;
            case LESS_THAN:
                return GREATER_OR_EQUAL;
            case GREATER_OR_EQUAL:
                return LESS_THAN;
            case LESS_OR_EQUAL:
                return GREATER_THAN;
            default:
                throw new IllegalStateException("Unknown operator");
        }
    }
}
